import api from '../../api'
export default {
    namespaced: true,// 是否开启命名空间
    state: {
        shopList: [],
        total: 0
    },
    mutations: {
        setShopList(state, data) {
            // state.shopList = data; // 赋值操作
            // 上拉加载 执行拼接
            state.shopList = state.shopList.concat(data)
        },
        setTotal(state,total) {
            state.total = total
        },
        clearShopList(state){
            state.shopList = []
        }
    },
    actions: {
        SET_SHOP_LIST(context, data) {
            return new Promise((resolve,reject) => {
                api.getShopList(data).then(res=>{
                    if(res.code === 1){
                        resolve(data)
                        // 列表
                        context.commit('setShopList', res.data.data)
                        // 总数
                        context.commit('setTotal', res.data.total)
                    } else {
                        reject(res.message)
                    }
                }).catch(err=>{
                    reject(err)
                })
            })
        }
    }
}